<?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
<!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="#">首页</a>
                        </li>
                        <li class="active">
                            <a href="#">器材分类管理</a>
                        </li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->
                <!-- Page Header -->
                <div class="page-header position-relative">
                    <!--Header Buttons-->
                    <div class="header-buttons">
                        <a class="sidebar-toggler" href="#">
                            <i class="fa fa-arrows-h"></i>
                        </a>
                        <a class="refresh" id="refresh-toggler" href="">
                            <i class="glyphicon glyphicon-refresh"></i>
                        </a>
                        <a class="fullscreen" id="fullscreen-toggler" href="#">
                            <i class="glyphicon glyphicon-fullscreen"></i>
                        </a>
                    </div>
                    <!--Header Buttons End-->
                </div>
                <!-- /Page Header -->
                <!-- Page Body -->
                <div class="page-body">
                    <div class="row">
                        <div class="col-xs-12 col-md-12">
                            <div class="tab-content tabs-flat no-padding">
                                <div id="visits" class="tab-pane active animated fadeInUp">
                                    <div class="row">
                                        <div class="col-lg-12 chart-container">
                                            <div id="dashboard-chart-visits" class="chart chart-lg no-margin">
                                                <div class="widget-body">
                                                        <div class="table-toolbar">
                                                            <a id="editabledatatable_new" href="javascript:void(0);"  class="addCat btn btn-default">
                                                                添加分类
                                                            </a>
                                                        </div>
                                                        <table class="table table-striped table-bordered table-hover" id="simpledatatable">
                                                            <thead>
                                                                <tr>
                                                                    <th style="width: 60px;">分类ID</th>
                                                                    <th>分类名称</th>
                                                                    <th>操作</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                             <?php
                                                              if (!empty($cat_list))
                                                              {
                                                                foreach ($cat_list AS $row)
                                                                {
                                                              ?>
                                                                <tr class="gradeX js_cat_level"   data_parentid="<?=$row['parent_id']?>" >
                                                                    <td class="center" style="text-align:center;width:40px;"><?=$row['cat_id']?></td>
                                                                    <td class="center">
                                                                         <?php if($row['p_level']):?>                                                                   
                                                                            <span style="padding-left:<?php echo $row['p_level']*30;?>px;">𠃊<?=$row['cat_name']?></span>
                                                                        <?php else:?>                                   
                                                                            <span style="font-weight:bold;"><?=$row['cat_name']?></span>
                                                                        <?php endif;?>
                                                                        <?php if($row['cover'] && $row['p_level']==2 ):?>
                                                                        <div style="float: right;"><img  src="<?=$row['cover']?>" width="120px" height="80px"  alt="/<?=$row['cover']?>"/></div>
                                                                        <?php endif;?>
                                                                    </td>
                                                                    <td  class="center " data_id="<?=$row['cat_id']?>">
                                                                        <a href='javascript:void(0);'  class="editCat">修改</a>
                                                                        <a  class="poi js_del">删除</a>
                                                                     
                                                                    </td>
                                                                </tr>
                                                            <?php
                                                                }
                                                              }
                                                              ?>
                                                            </tbody>
                                                        </table>
                                                    </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Page Body -->
        </div>
        <!-- /Page Content -->
<script src="<?php echo STATICURL; ?>js/jquery-2.0.3.min.js"></script>
<script src="<?php echo STATICURL; ?>layer/layer.js"></script>
<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script>
    $(document).ready(function(){
        $('.addCat').on('click', function(){
            //iframe窗
            layer.open({
                type: 2,
                title: '添加',
                shade: [0.5, '#000'],
                shadeClose: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['550px', '240px'],
                content: '/luckydog/category/add'
            });
        });
        $('.editCat').on('click', function(){
            //iframe窗
            var id = $(this).parent().attr("data_id");
            layer.open({
                type: 2,
                title: '修改',
                shade: [0.5, '#000'],
                shadeClose: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['550px', '240px'],
                content: '/luckydog/category/edit?id='+id
            });
        });
        $(".js_del").click(function(){
            var cat_id = $(this).parent().attr("data_id");
            var tmp = $(this).parents(".js_cat_level");
            var next_parentid = tmp.next("tr").attr("data_parentid");
            var flag = 0;
            
            if(confirm("确定删除当前分类吗?")){
                $.post("/luckydog/category/do_del", {cat_id:cat_id}, function(data) {               
                    if (data.status) {     
                        layer.msg("删除成功");             
                        window.location.href = "/luckydog/category";
                    }else{
                        layer.msg("删除失败");
                        window.location.href = "/luckydog/category";
                    }
                }, "json");

            }                 
            
        });     
    });
</script>



